# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Aaron Griffin <aaron@archlinux.org>
# Contributor: Neil Lin <neil@vip.url.com.tw>
# Contributor: Cravix < dr dot neemous at gmail dot com >

pkgname=stardict
pkgver=3.0.7
pkgrel=1
pkgdesc='International dictionary software'
arch=('loong64' 'x86_64')
url='http://stardict-4.sourceforge.net/'
license=('GPL')
depends=('gtk3' 'libsigc++' 'libcanberra')
makedepends=('enchant' 'espeak-ng' 'mariadb-libs' 'pcre' 'yelp-tools' 'gnome-common')
optdepends=('enchant: spell checker plugin'
            'espeak-ng: text to speech plugin')
options=('!emptydirs')
source=("https://downloads.sourceforge.net/project/stardict-4/$pkgver/$pkgname-$pkgver-2-src.7z"
        'mariadb.patch')
sha256sums=('d766f4efb1ae868855a47f39b2def66dd7a3232ca54c651c9cb3327b1bec50ea'
            '5be4d0468f6089b760924a5d25030110ca62869b4611afb46a411cd4eb59b832'
            'f66b916c358bddf48fcb91a7d0190a7109fe92a1388ec982c47dfa9ac1ee69cf')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ../mariadb.patch

  sed -i 's/, enchant/, enchant-2/' dict/configure.ac
  sed -i '/AM_GCONF_SOURCE_2/d' dict/configure.ac
  sed -i '/GNOME_DOC_INIT/d' dict/configure.ac
  sed -i '/gnome-doc-utils.make/d' dict/help/Makefile.am
  sed -i 's|espeak/speak_lib.h|espeak-ng/speak_lib.h|' dict/configure.ac dict/stardict-plugins/stardict-espeak-tts-plugin/stardict_espeak.cpp
  sed -i 's/ESPEAK_LIBS="-lespeak"/ESPEAK_LIBS="-lespeak-ng"/' dict/configure.ac

  ./autogen.sh
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  CFLAGS=${CFLAGS/-Werror=format-security/}
  CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
  CXXFLAGS+=" -std=gnu++11"
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --mandir=/usr/share/man \
    --disable-gnome-support \
    --disable-gucharmap \
    --disable-festival \
    --disable-flite \
    --disable-updateinfo
  sed -e 's/ -shared / -Wl,-O1,--as-needed\0/g' -i {dict,lib,tools}/libtool
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
